home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_540 / browser / browserii_src.lzh / String.c < prev    next >
C/C++ Source or Header  |  1991-05-08  |  3KB  |  143 lines

  1. /*
  2.  *    String.c - Copyright © 1991 by S.R. & P.C.
  3.  *
  4.  *    Created:    10 Mar 1991  16:47:13
  5.  *    Modified:    01 May 1991  15:14:32
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. #include "Global.h"
  11. #include "DosVar.h"
  12. #include "proto/String.h"
  13.  
  14.  
  15. /*
  16.  *    size of sub-strings. Theses values are also in SPrintf() format strings, and
  17.  *    they need to be same. Changes MUST be made in all places if these values have
  18.  *    to be modified.
  19.  */
  20.  
  21. #define SIZE_LEN    9
  22. #define BLOCKS_LEN    7
  23. #define PROTECT_LEN    10
  24. #define DATE_LEN    19
  25. #define KEY_LEN        10
  26.  
  27.  
  28. /* Copy and convert to upper case a string */
  29.  
  30. void UStrcpy(char *dst, char *src)
  31. {
  32.     while(*dst++ = Toupper(*src++));
  33. }
  34.  
  35.  
  36. void Date2String(struct DateStamp *ds, char *dest)
  37. {
  38.     struct DateTime dt;
  39.  
  40.     dt.dat_Stamp = *ds;
  41.     dt.dat_Format = FORMAT_DOS;
  42.     dt.dat_Flags = DTF_FUTURE;    /* Print real dates, not "Future", "Tomorrow", ... */
  43.     dt.dat_StrDay = NULL;
  44.     dt.dat_StrDate = dest;
  45.     dt.dat_StrTime = dest + LEN_DATSTRING;
  46.     if (StamptoStr(&dt))
  47.         strcpy(dest, "  Invalid         ");
  48.     dest[9] = ' ';        /* replace '\0' with a space between date and time strings */
  49.     dest[18] = '\0';    /* It seems not to be done by StamptoStr() ! */
  50. }
  51.  
  52.  
  53. static void MakeProtectString(LONG Protection, char *dest)
  54. {
  55.     static char *ProtectChar = "chsparwed";
  56.     short i;
  57.  
  58.     for( i=0 ; i<9; i++ )
  59.         *dest++ = (Protection & 0x100>>i) ? ProtectChar[i] : '-';
  60.     *dest = '\0';
  61. }
  62.  
  63.  
  64. void FreePrintStrings(struct BrowserWindow *Win)
  65. {
  66.     struct ScrollEntry *S;
  67.     short i;
  68.  
  69.     for( i=0 ; i<Win->bw_ShownEntries ; i++ ) {
  70.         S = Win->bw_EntryArray[i];
  71.         if (S->se_Print) {
  72.             FreeMem(S->se_Print, Win->bw_PrintStringLen+1);
  73.             S->se_Print = NULL;
  74.         }
  75.     }
  76. }
  77.  
  78.  
  79. void BuildPrintString(struct BrowserWindow *Win, struct ScrollEntry *S)
  80. {
  81.     char *s;
  82.     char buf[20];
  83.  
  84.     s = S->se_Print;
  85.     SPrintf(s, Win->bw_Fmt, S->se_FileInfo.fi_Name);
  86.     s += Win->bw_MaxFilenameLen;
  87.     if (Win->bw_EntryInfoFlags & DISPLAY_KEY) {
  88.         SPrintf(buf, "[%ld]", S->se_FileInfo.fi_DiskKey);
  89.         SPrintf(s, "%10s", buf);
  90.         s += KEY_LEN;
  91.     }
  92.     if (Win->bw_EntryInfoFlags & DISPLAY_SIZE) {
  93.         if (S->se_FileInfo.fi_Type == DLX_FILE)
  94.             SPrintf(s, "%9ld", S->se_FileInfo.fi_Size);
  95.         else
  96.             strcpy(s, "    (dir)");
  97.         s += SIZE_LEN;
  98.     }
  99.     if (Win->bw_EntryInfoFlags & DISPLAY_BLOCK) {
  100.         SPrintf(s, "%7ld", S->se_FileInfo.fi_NumBlocks);
  101.         s += BLOCKS_LEN;
  102.     }
  103.     if (Win->bw_EntryInfoFlags & DISPLAY_PROTECT) {
  104.         *s++ = ' ';
  105.         MakeProtectString(S->se_FileInfo.fi_Protection, s);
  106.         s += PROTECT_LEN-1;
  107.     }
  108.     if (Win->bw_EntryInfoFlags & DISPLAY_DATE) {
  109.         *s++ = ' ';
  110.         Date2String(&S->se_FileInfo.fi_Date, s);
  111.     }
  112. }
  113.  
  114.  
  115. BOOL BuildPrintStrings(struct BrowserWindow *Win)
  116. {
  117.     static short LenTab[] = { SIZE_LEN, BLOCKS_LEN, PROTECT_LEN, DATE_LEN, KEY_LEN };
  118.     struct ScrollEntry *S;
  119.     short len, i;
  120.  
  121.     FreePrintStrings(Win);
  122.     if (Win->bw_NewMaxFilenameLen > Win->bw_MaxFilenameLen)
  123.         Win->bw_MaxFilenameLen = Win->bw_NewMaxFilenameLen;
  124.     Win->bw_NewMaxFilenameLen = 0;
  125.     len = Win->bw_MaxFilenameLen;
  126.     SPrintf(Win->bw_Fmt, "%%-%ds", len);
  127.     for( i=0 ; i<5 ; i++ ) {
  128.         if (Win->bw_EntryInfoFlags & 1<<i)
  129.             len += LenTab[i];
  130.     }
  131.     Win->bw_PrintStringLen = len;
  132.     len++;
  133.     for( i=0 ; i<Win->bw_ShownEntries ; i++ ) {
  134.         S = Win->bw_EntryArray[i];
  135.         if (!(S->se_Print = AllocMem(len, MEMF_PUBLIC)))
  136.             return FALSE;
  137.         BuildPrintString(Win, S);
  138.     }
  139.     return TRUE;
  140. }
  141.  
  142.  
  143.